MODULE MOD_WRF
  USE MOD_BULK
  USE MOD_SURFACEFORCE
  USE all_vars
  USE MOD_UTILS
  USE MOD_NCTOOLS
  USE MOD_PAR
  implicit none
  
  
  TYPE(INTERP_WEIGHTS),POINTER :: WRF_INTP_N,WRF_INTP_C
  
  
CONTAINS
  
  

  SUBROUTINE LOAD_WRF(FNAME)
    USE MOD_FORCE
    IMPLICIT NONE
    CHARACTER(LEN=*), INTENT(IN) :: FNAME
    TYPE(NCFILE), POINTER :: NCF
    LOGICAL :: FOUND

    river_number = 0

    HEATING_ON   = .TRUE.
    HEATING_FILE = FNAME
    HEATING_KIND =VRBL

    WIND_ON   = .TRUE.
    WIND_FILE = FNAME
    WIND_KIND =VRBL
    WIND_TYPE = stress

    PRECIPITATION_ON   = .TRUE.
    PRECIPITATION_FILE = FNAME
    PRECIPITATION_KIND = VRBL

# if defined (ICE)
    ICE_MODEL        = .TRUE.
    ICE_FORCING_FILE = FNAME
    ICE_FORCING_KIND = VRBL
# endif

#   if defined (AIR_PRESSURE)
    AIRPRESSURE_ON   = .TRUE.
    AIRPRESSURE_FILE = FNAME
    AIRPRESSURE_KIND =VRBL
# endif

    CALL  NC_INIT(NCF,FNAME)

    ! OPEN THE FILE AND LOAD METADATA
    if(.not. NCF%OPEN) then
       Call NC_OPEN(NCF)
       CALL NC_LOAD(NCF)
       FILEHEAD => ADD(FILEHEAD,NCF)
    end if


    CALL SETUP_FORCING

!!$! TESTING FOR INTERP - ALLOWS OUTPUT OF MASKED DATA METHOD
!!$    NCF => FIND_FILE(FILEHEAD,FNAME,FOUND)
!!$    call print_file(NCF)
!!$
!!$    WRF_INTP_N=>NCF%INTERP_N
!!$    WRF_INTP_C=>NCF%INTERP_C


  END SUBROUTINE LOAD_WRF
  


  SUBROUTINE UPDATE_WRF(NOW)
    USE MOD_FORCE
    USE ALL_VARS
    IMPLICIT NONE
    TYPE(TIME) :: NOW
        CALL UPDATE_WIND(NOW,WUSURF,WVSURF)
        CALL UPDATE_PRECIPITATION(NOW,QPREC,QEVAP)
        CALL UPDATE_HEAT(NOW,SWRAD_WATTS,WTSURF_WATTS)

#   if defined (AIR_PRESSURE)
        CALL UPDATE_AIRPRESSURE(NOW,PA_AIR)
# endif

# if defined (ICE)
        CALL UPDATE_ICE(NOW,T_AIR,SWRAD_WATTS,QA_AIR,CLOUD)
# endif

  END SUBROUTINE UPDATE_WRF



END MODULE MOD_WRF
